package com.zbmy.plugin.im.server.config;

import java.util.concurrent.ThreadPoolExecutor;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import com.base.framework.utils.SnowflakeIdFactory;

/**
 * bean 配置类   
 * @ClassName: WebConfig    
 * @author 陈剑飞    
 * @date 2018年4月12日 下午6:01:16    
 * @version  v 1.0
 */
@Configuration
public class BeanConfig {
	@Value("${worker.id:1}")
	private Long workerId;
	@Value("${datacenter.id:1}")
	private Long datacenterId;
	
	@Bean
	public ThreadPoolTaskExecutor getTaskExecutor(){
		ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
		taskExecutor.setCorePoolSize(10);
		taskExecutor.setKeepAliveSeconds(200);
		taskExecutor.setMaxPoolSize(100);
		taskExecutor.setQueueCapacity(500);
		taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
		return taskExecutor;
	}
	
	@Bean
	public SnowflakeIdFactory  getSnowflakeIdFactory() {
		return new SnowflakeIdFactory(workerId , datacenterId);
	}
}
